package com.mvc.common;

import java.util.Map;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import com.mvc.annotation.AnnotationHandler;
import com.mvc.annotation.AnnotationProxy;
import com.mvc.annotation.IActionAnnotation;
import com.mvc.util.MvcUtil;


@WebListener
public class MvcListener implements ServletContextListener {

    
    public MvcListener() {
    }

	
    public void contextInitialized(ServletContextEvent arg0) {
    	String actionPackages = arg0.getServletContext().getInitParameter("actionPackages");
    	System.out.println("context initialized parameter - actionPackages: " + actionPackages);
    	
    	IActionAnnotation actionAnnotation = (IActionAnnotation)AnnotationProxy.getAnnotationFactory(AnnotationHandler.class);
    	Map<String,String> hashMap = actionAnnotation.getActionAnnotation(actionPackages);
    	arg0.getServletContext().setAttribute(MvcUtil.APPLITION_MVC_MAPPING, hashMap);
    }


    public void contextDestroyed(ServletContextEvent arg0) {
    }
	
}
